package com.qk.management.service.impl;

import com.qk.management.annotation.LogAnno;
import com.qk.result.PageResult;
import com.qk.entity.Dept;
import com.qk.management.mapper.DeptMapper;
import com.qk.management.service.DeptService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
/**
 * @Author:zhengbowen
 * @Date: 2025/10/06 16:18
 * @Description: 部门管理业务逻辑
 */
@Service
@RequiredArgsConstructor
public class DeptServiceImpl implements DeptService {

    private final DeptMapper deptMapper;

    @Override
    @LogAnno
    public void insertDept(Dept dept) {
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.insertDept(dept);
    }

    @Override
    public PageResult<Dept> selectByPage(Integer page, Integer pageSize, String name, Integer status) {
        page = (page - 1) * pageSize;
        return PageResult.<Dept>builder()
                .total(deptMapper.selectCount(name, status))
                .rows(deptMapper.selectByPage(page, pageSize, name, status))
                .build();
    }

    @Override
    @LogAnno
    public void deleteDept(Integer id) {
        deptMapper.deleteDept(id);

    }

    @Override
    public Dept selectDeptById(String id) {
        return deptMapper.selectDeptById(id);
    }

    @Override
    @LogAnno
    public void updateDept(Dept dept) {
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.updateDept(dept);
    }

    @Override
    public List<Dept> selectDeptsList() {

        return deptMapper.selectDeptsList();
    }
}